﻿using Game;
using Game.Lib;
using System.IO;
using System;

namespace UnitTester
{
    public partial class Program
    {
        static void Main(string[] args)
        {
            ztTypesSerializationTest();
            ztTypesOperatorTest();
            ztTypesMethodTest();
            ztPacketTest();
            UDPServerTest();

            Console.Read();
        }

        private static void Assert(bool a, string name)
        {
            if (a) Console.WriteLine("Assertion \"" + name + "\" passed");
            else throw new Exception("Assertion \"" + name + "\" failed.");
        }

        private static void DoSerializationTest(Serializable a, string name)
        {
            System.Console.WriteLine("Doing serialization test \"" + name + "\"");
            byte[] data = a.ToBytes();
            Serializable test = (Serializable)a.GetType().GetConstructor(new Type[0]).Invoke(new object[0]);
            test.Deserialize(new MemoryStream(data));
            if (!a.Equals(test)) throw new Exception("Serialization unit test \"" + name + "\" failed\nExpected " + a.ToString() + "\nRecieved " + test.ToString() + "\n");

            MemoryStream ms = new MemoryStream();
            a.Serialize(ms);
            ms.Position = 0;
            test.Deserialize(ms);
            if (!a.Equals(test)) throw new Exception("Serialization unit test \"" + name + "\" failed\nExpected " + a.ToString() + "\nRecieved " + test.ToString() + "\n");
        }
    }
}
